package com.superhero.miniprogram.controller;

import com.superhero.common.pojo.ApiResult;
import com.superhero.common.pojo.WxLoginInput;
import com.superhero.common.pojo.vo.WxLoginOutput;
import com.superhero.miniprogram.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@Api(tags = {"登录/注册"})
@RestController
@RequestMapping("/miniprogram/auth")
public class LoginController {

    @Resource
    LoginService loginService;

    @ApiOperation(value = "微信授权登录", notes = "简易鉴权登录")
    @PostMapping("/wxLogin")
    public ApiResult<WxLoginOutput> wxLogin(@Valid WxLoginInput input) throws WxErrorException {
        return loginService.wxLogin(input);
    }

    @ApiOperation(value = "检查人员登录", notes = "检查人员登录")
    @PostMapping("/normalLogin")
    public ApiResult<WxLoginOutput> normalLogin(@NotNull String username, @NotNull String password) {
        return loginService.normalLogin(username, password);
    }

}
